<% @page_title = "#{h @group.title} - #{h @topic.title} | 多背一公斤 - 灾后学校重建计划" -%>

<% content_for :sidebar do -%>
  <h2><%= link_to "写新话题", new_topic_url(@group.id) %></h2>
  <h2><%= link_to "返回#{h @group.title}小组", group_url(@group.id) %></h2>
  <%= render :partial => "/groups/all_groups" %>
<% end -%>


<h1><%= h @topic.title %></h1>
<div style="float:right">
  <%= avatar_for(@topic.user, "large") %>
</div>
<h2><%= link_to @topic.user.login, user_url(@topic.user.id) %> 写于 <%= show_datetime @topic.created_at %></h2>
<%= @topic.content_html %>

<% if @topic.editable_by?(current_user) -%>
  <p style="text-align:right"><%= link_to "修改", edit_topic_url(@group.id, @topic.id) %> <%= link_to "删除", topic_url(@group.id, @topic.id), :method => 'delete', :confirm => "确定要删除么？" %></p>
<% end -%>

<% @posts.each do |post| -%>
  <div class="cmt-item" style="margin-bottom:10px">
    <div style="float:left;margin:0 8px 0 0">
      <%= avatar_for post.user, "large" %><br />
    </div>
    <div style="margin-left:50px">
      <div>
        <div style="background-color:#ffc">
          <% if post.editable_by?(current_user) -%>
          <span style="float:right">
            <%= link_to "修改", edit_post_url(@group.id, @topic.id, post.id) %>
            <%= link_to "删除", post_url(@group.id, @topic.id, post.id), :method => 'delete', :confirm => "确定要删除么？" %>
          </span>
          <% end -%>
          <h2><%= link_to post.user.login, user_path(post.user) %><span class="tip"> 写于 <%= show_datetime post.created_at %></span></h2>
        </div>
      </div>
      <div><%= post.content_html %></div>
    </div>
  </div>
<% end -%>

<h2>你的回复 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<% form_for :post, :url => posts_url(@group.id, @topic.id) do |f| -%>
  <p><%= f.text_area :content, :rows => 6 %></p>
  <%= submit_tag "写好了，提交" %>
<% end -%>